home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10516 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: operator % - compiler error
  5. Date: Mon, 18 Mar 96 13:54:11 GMT
  6. Organization: none
  7. Message-ID: <827157251snz@genesis.demon.co.uk>
  8. References: <4ihuuh$6ul@hatathli.csulb.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!genesis.demon.co.uk
  13.  
  14. In article <4ihuuh$6ul@hatathli.csulb.edu> davidcho@csulb.edu "David Cho" writes:
  15.  
  16. >When I try to compile, I get an erro message for the following line:           
  17. >
  18. >
  19. >x=663608941*y%pow(2,32)  /*I want remainder*/
  20. >
  21. >But the error message says "illegal use of floating point".  What does 
  22. >that mean?  Isn't % used a an operator to calcuate the remainder?
  23.  
  24. Yes, it calcuates integer remainder and it requires its operands to be
  25. integers. pow() returns a double result which is not suitable. You need to
  26. provide more information about what you want to do. There is no guarantee
  27. that any C inreger type can hold 2 to the power of 32. You need to be clear
  28. about what types x and y have - it looks like they need to be unsigned long
  29. here to avoid overflow problems. Maybe what you need is:
  30.  
  31. x = (663608941 * y) & 0xffffffff;
  32.  
  33. which also avoids a costly and potentially inaccurate mathematical function.
  34.  
  35. -- 
  36. -----------------------------------------
  37. Lawrence Kirby | fred@genesis.demon.co.uk
  38. Wilts, England | 70734.126@compuserve.com
  39. -----------------------------------------
  40.